package com.hclc.yxb.shiro;//package com.hclc.stq.console.shiro;
//
//import com.hclc.stq.model.contans.ApiConst;
//import com.hclc.stq.model.result.ResultEntity;
//import com.hclc.stq.util.json.JsonUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
//
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.PrintWriter;
//
///**
// * @Author: hef
// * shiro过滤器
// * @Date: Create in 1:39 下午 2020/9/23
// */
//@Slf4j
//public class CORSAuthenticationFilter extends FormAuthenticationFilter {
//
//    public CORSAuthenticationFilter() {
//        super();
//    }
//
//    @Override
//    public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
//        //Always return true if the request's method is OPTIONSif (request instanceof HttpServletRequest) {
//        if (((HttpServletRequest) request).getMethod().toUpperCase().equals("OPTIONS")) {
//            return true;
//        }
//
//        return super.isAccessAllowed(request, response, mappedValue);
//    }
//
//    @Override
//    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
//        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
//        httpServletResponse.setContentType("application/json; charset=utf-8");
//        httpServletResponse.setHeader("Access-Control-Allow-Credentials","true");
//        httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
//        httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
//        httpServletResponse.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
//        httpServletResponse.setHeader("Cache-Control", "no-cache");
//        PrintWriter writer = httpServletResponse.getWriter();
//        writer.write(JsonUtil.toJson(ResultEntity.ResultFail(ApiConst.CODE_FAIL_TOKEN, ApiConst.DESC_FAIL_TOKEN)));
//        writer.close();
//        return false;
//    }
//}
